﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CCApLMCopyLocationOrientationApp
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public class CCApLMCopyLocationOrientationApp : CCApLMLocationsApp
{
  private List<ITxObject> m_failedToCopyList = new List<ITxObject>();

  public void CopyLocationOrientation(TxObjectList locations, TxTransformation absLoc)
  {
    int num1 = 0;
    foreach (ITxObject location in (Collection<ITxObject>) locations)
    {
      if (this.copyLocOrientation(location as ITxLocatableObject, absLoc))
        ++num1;
    }
    if (num1 > 0)
      TxApplication.RefreshDisplay();
    if (this.m_failedToCopyList.Count <= 0)
      return;
    string str1 = Environment.NewLine + this.m_failedToCopyList[0].Name;
    for (int index = 1; index < this.m_failedToCopyList.Count; ++index)
      str1 = $"{str1} ,{this.m_failedToCopyList[index].Name}";
    string str2 = str1 + ".";
    this.m_failedToCopyList.Clear();
    int num2 = (int) TxMessageBox.ShowModal(string.Format(StringTable.FAILED_TO_COPY, (object) str2), StringTable.COPY_LOC_NAME, MessageBoxButtons.OK, MessageBoxIcon.Hand);
  }

  private bool copyLocOrientation(ITxLocatableObject objToChange, TxTransformation refAbsLoc)
  {
    bool flag = false;
    TxTransformation absoluteLocation1 = objToChange.AbsoluteLocation;
    if (TxTransformation.op_Inequality(refAbsLoc, absoluteLocation1))
    {
      TxTransformation absoluteLocation2 = objToChange.AbsoluteLocation;
      objToChange.AbsoluteLocation = new TxTransformation()
      {
        RotationRPY_XYZ = refAbsLoc.RotationRPY_XYZ,
        Translation = absoluteLocation1.Translation
      };
      if (new CApMlmLocationsValidation((ITxObject) objToChange).GetLocationStatus((LocationStatusCheck) 1) == 1)
      {
        objToChange.AbsoluteLocation = absoluteLocation2;
        this.m_failedToCopyList.Add((ITxObject) objToChange);
      }
      else
        flag = true;
    }
    return flag;
  }
}
